package com.dgl.sdk.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePreStore {
	private static SharedPreferences mShareConfig;
	
	public static void init(Context context){
		
		if(mShareConfig == null){
			mShareConfig = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
		}
		
	}
	
    public static void save(String key, String value) {
        if (Utils.notNull(mShareConfig)) {
            Editor conEdit = mShareConfig.edit();
            conEdit.putString(key.trim(), value.trim());
            conEdit.commit();
        }
    }

    public static void save( String key, int value) {
        if (Utils.notNull(mShareConfig)) {
            Editor conEdit = mShareConfig.edit();
            conEdit.putInt(key, value);
            conEdit.commit();
        }
    }

    /**
     * 添加公共信息
     * 
     * @param key
     * @param value
     */
    public static void save(String key, boolean value) {
        if (Utils.notNull(mShareConfig)) {
            Editor conEdit = mShareConfig.edit();
            conEdit.putBoolean(key, value);
            conEdit.commit();
        }
    }

    /**
     * 添加公共信息
     * 
     * @param key
     * @param value
     */
    public static void save(String key, Long value) {
        if (Utils.notNull(mShareConfig)) {
            Editor conEdit = mShareConfig.edit();
            conEdit.putLong(key, value);
            conEdit.commit();
        }
    }
    
    public static String readString(String key) {
        String value = null;
        if (null != mShareConfig) {
            value = mShareConfig.getString(key, "");
        }
        return value;
    }
    public static int readInt(String key) {
    	int value = 0;
    	if (null != mShareConfig) {
    		value = mShareConfig.getInt(key, 0);
    	}
    	return value;
    }
    
    public static int getIntByKey(String key) {
    	int value = 0;
    	if (null != mShareConfig) {
    		value = mShareConfig.getInt(key, 0);
    	}
    	return value;
    }
}
